package com.hhh.Pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
//    1为成功，0 为失败
    private Integer code;
//    返回给前端的数据
    private T data;
//    错误信息
    private String msg;
//    动态数据
    private Map  map =new HashMap<>() ;

    public static <T> Result<T> success(T object)
    {
        Result<T> result=new Result<>();
        result.data=object;
        result.code=1;
        return result;
    }

    public static <T> Result<T> error(String msg)
    {
        Result<T> result=new Result<>();
        result.code=0;
        result.msg=msg;
        return result;
    }

    public  <T> Result<T> Add(String key,Object value)
    {
        this.map.put(key, value);
        return (Result<T>) this;
    }
}
